// component/SearchOper/SearchOper.js

import request from '../../utils/config.js';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    Search: {
      type: Boolean,
      value: false
    },
    operList:{
      type:Array,
      value:[]
    },
    operList: {
      type: Array,
      value: []
    },
    searchValue:{
      type:String,
      value:''
    },
    searchTag: {
      type: Array,
      value: []
    },
    tempOperList: {
      type: Array,
      value: []
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    windowHeight:wx.getSystemInfoSync().windowHeight,
    ossImgUrL: 'https://winhc.oss-cn-shanghai.aliyuncs.com/xcx/',
    operList:[],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //搜索框触发事件
    changeKey: function (e) {
      let value = e.detail.value;
      this.setData({
        searchValue: value
      });
      //开始出发搜索条件
      var tempOperList = new Array();
      var operList = this.data.operList;
      var searchTag = this.data.searchTag;
      if (value) {
        for (let i=0;i< operList.length;i++) {
          let slt=false;
          for (let j=0;j<searchTag.length;j++){
            if (searchTag[j].type=='tags'){
              if (operList[i].tagCodes.length>0){
                operList[i].tagCodes.map((item) => {
                  searchTag[j].value.map((item2) => {
                    if (item == item2) {
                      slt = true;
                      return;
                    }
                  });
                  if (slt) { return }
                });
              }
            } else if (searchTag[j].type == 'all'){
              slt = true;
            }
          }
          //以上过滤条件
          if (slt&&operList[i].realName) {
            if (operList[i].realName.indexOf(value) != -1) {
              tempOperList.push(operList[i]);
            }
          }
        }
      }

      this.setData({
        tempOperList: tempOperList
      });
    },
    operListTap:function(e){
      // console.log(e)
      this.setData({
        Search: false,
      })
      this.triggerEvent("select", JSON.stringify(e.currentTarget.dataset.info));
    },
    // 取消搜索
    hideTopSearch: function () {
      this.setData({
        Search: false,
      })
    },

    //搜索框聚焦
    keyFocus: function () {
      this.setData({
        showKeyDel: "block"
      });
    },

    //搜索框失焦
    keyBlur: function () {
      this.setData({
        showKeyDel: "none"
      });
    }, //清除搜索框事件
    delKeyTap: function () {
      this.setData({
        searchValue: "",
        tempOperList: []
      });
      this.triggerEvent("select",'');
    },
  }
})
